"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
(() => {
    const add = function (x, y) {
        return x + y;
    };
    let sum = add(1, 2);
    console.log('sum:', sum);
    // ts 完整的函数写法
    const add2 = function (x, y) {
        return x + y;
    };
    sum = add2(3, 4);
    console.log('sum:', sum);
    // 剩余参数
    function buildName(firstName, ...restOfName) {
        return firstName + " " + restOfName.join(" ");
    }
    let employeeName = buildName("Joseph", "Samuel", "Lucas", "MacKinzie");
    console.log('employeeName', employeeName);
    // 可选参数，用问号标示，需要注意的是，可选参数只能在必选参数之后
    function buildName2(firstName, midName, lastName) {
        if (lastName) {
            return firstName + '_' + midName + '_' + lastName;
        }
        return firstName + '_' + midName;
    }
    // 默认参数
    function buildName3(firstName = '古月', midName, lastName) {
        if (lastName) {
            return firstName + '_' + midName + '_' + lastName;
        }
        return firstName + '_' + midName;
    }
    // 函数重载：函数名
    function add3(x, y) {
        if (typeof x === 'number' && typeof y === 'number')
            return x + y;
        else if (typeof x === 'string' && typeof y === 'string')
            return (parseInt(x) + parseInt(y));
        return 0;
    }
    let x = add3('4', '5');
    console.log(x);
    let name = buildName2('古月', '屠龙', '倚天');
    name = buildName2('古月', '屠龙');
    console.log(name);
    name = buildName3(undefined, '倚天'); // 古月_屠龙
    name = buildName3(null, '倚天'); // null_倚天
    name = buildName3('', '倚天'); // _倚天
    console.log(name);
})();
